const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin');

module.exports = {
  context: path.join(__dirname,''),
  entry: './entry-server.js',
  output: {
    path: path.join(__dirname,'dist'),
    libraryTarget: 'commonjs2',
    filename: 'server-bundle.js'
  },
  target: 'node',
  devtool: '#source-map',
  module: {
    rules:[
      {
        test: /.js$/,
        use: [{loader: 'babel-loader'}],
        exclude: /node_modules(?!(\/|\\).*(weex).*)/
      },
      {
        test: /\.vue(\?[^?]+)?$/,
        use: [{
          loader: 'vue-loader',
          options: {
            compilerModules: [
              {
                postTransformNode: el => {
                  el.staticStyle = `$processStyle(${el.staticStyle})`
                  el.styleBinding = `$processStyle(${el.styleBinding})`
                }
              }
            ]
          }
        }]
      }
    ]
  },
  externals: [nodeExternals({
    whitelist: /\.css$/
  })],
  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
      'process.env.VUE_ENV': '"server"'
    }),
    new VueSSRServerPlugin()
  ]
}